package com.xiaoq.coms;

import org.springframework.http.ResponseEntity;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonProperty;

import io.swagger.annotations.ApiModelProperty;

@JsonAutoDetect(fieldVisibility = Visibility.NONE, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE)
@JsonInclude(value = JsonInclude.Include.NON_NULL)
@JsonIgnoreProperties(ignoreUnknown = true)
public class GenericResponse {
	/** 正常状态码，0000， */
	public static final String CODE_OK = "0000";
	
	/** 异常态码，9999 */
	public static final String CODE_NG = "9999";
	
	@ApiModelProperty(name = "rc", value = "响应码", position=0)
	@JsonProperty("rc")
	private String rc;
	
	@ApiModelProperty(name = "msg", value = "提示消息", position=1)
	@JsonProperty("msg")
	private String msg;
	
	private static final GenericResponse OK_RESP = new GenericResponse(CODE_OK);
	
	public GenericResponse() {
		
	}
	
	public GenericResponse(String rc) {
		this.rc = rc;
	}
	
	public GenericResponse(String rc, String msg) {
		this.rc = rc;
		this.msg = msg;
	}
	
	public static final ResponseEntity<?> ok() {
		return ResponseEntity.ok(OK_RESP);
	}
	
	public static final ResponseEntity<?> ng(String msg) {
		GenericResponse resp = new GenericResponse(CODE_NG);
		resp.setMsg(msg);
		return ResponseEntity.ok(resp);
	}
	
	public static final ResponseEntity<?> ngWithCode(String msg,String code) {
		GenericResponse resp = new GenericResponse(code);
		resp.setMsg(msg);
		return ResponseEntity.ok(resp);
	}

	public String getRc() {
		return rc;
	}

	public void setRc(String rc) {
		this.rc = rc;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
	
}
